package com.ltkj.baseplatform.controller;

import com.ltkj.baseplatform.domain.req.PositionReq;
import com.ltkj.common.core.utils.LocationUtils;
import com.ltkj.common.core.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 定位
 * 
 * @author ruoyi
 */
@Api(tags = "定位")
@RestController
@RequestMapping("/position")
public class PubPositionController
{

    /**
     * 计算两个位置的距离
     */
    @ApiOperation("计算两个坐标点距离")
    @PostMapping("/getDistance")
    public AjaxResult getDistance(@Validated @RequestBody PositionReq positionReq)
    {
        double lat1 = Double.parseDouble(positionReq.getLat1());
        double lng1 = Double.parseDouble(positionReq.getLng1());
        double lat2 = Double.parseDouble(positionReq.getLat2());
        double lng2 = Double.parseDouble(positionReq.getLng2());
        double distance = LocationUtils.getDistance(lat1, lng1, lat2,lng2);
        return AjaxResult.success("", Double.toString(distance));
    }
}
